package com.bw.module_service

import androidx.fragment.app.viewModels
import androidx.recyclerview.widget.GridLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.bw.lib_common.arouter.Router
import com.bw.lib_common.base.BaseFragment
import com.bw.module_service.adapter.ServiceAdapter
import com.bw.module_service.databinding.FragmentServiceBinding
import com.bw.module_service.model.ServiceModel
import com.bw.module_service.viewmodel.ServiceViewModel
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
@Route(path = Router.Ui.ServiceFragment)
class ServiceFragment : BaseFragment<ServiceViewModel,FragmentServiceBinding>() {
    override val mLayoutResId: Int
        get() = R.layout.fragment_service


    private val mViewModel:ServiceViewModel by viewModels()

    val mAdapter : ServiceAdapter by lazy {
        ServiceAdapter()

        ServiceAdapter().apply {
            onItemClick = { serviceModel ->
                when (serviceModel.title) {
                    "车辆管理" -> ARouter.getInstance().build(Router.Ui.CarManagerActivity).navigation()
                    "车位管理" -> ARouter.getInstance().build(Router.Ui.CarSpaceManagerActivity).navigation()
                    "维修管理" -> ARouter.getInstance().build(Router.Ui.RepairManagerActivity).navigation()
                    "房源信息" -> ARouter.getInstance().build(Router.Ui.PropertyActivity).navigation()
                    "月卡会员" ->  ARouter.getInstance().build(Router.Ui.MonthVipActivity).navigation()
                    "巡检管理" ->  ARouter.getInstance().build(Router.Ui.InspectionActivity).navigation()
                    "考勤管理" ->  ARouter.getInstance().build(Router.Ui.SignActivity).navigation()
                    "访客管理" ->  ARouter.getInstance().build(Router.Ui.VisitActivity).navigation()
                    "设备管理"  ->ARouter.getInstance().build(Router.Ui.DeviceActivity).navigation()
                    "公告管理" ->  ARouter.getInstance().build(Router.Ui.NoticeActivity).navigation()
                }
            }
        }
    }

    override fun initView() {
        mViewModel.initList()
        initAdapter()
    }

    //数据
    override fun initData() {

    }

    //请求接口
    override fun initListener() {

    }

    private fun initAdapter() {
        mAdapter.setData(mViewModel.serviceList)
        mBinding.rvService.layoutManager  = GridLayoutManager(context,3)
        mBinding.rvService.adapter = mAdapter
    }
}